﻿package com.gamemeal.filters{
	import flash.filters.BitmapFilter;
	import flash.filters.BlurFilter;
	import flash.filters.ColorMatrixFilter;
	import flash.filters.ConvolutionFilter;
	/**
	 * @author Colin
	 */
	public class FilterPreset {
		public static function getBlackWhiteHighContrastFilter(contrast:Number=100):BitmapFilter{
			var filter : BitmapFilter;
			if(contrast>=100){
				filter = new ColorMatrixFilter([3.3946001529693604,6.703399658203125,0.9020000100135803,0,-635,3.3946001529693604,6.703399658203125,0.9020000100135803,0,-635,3.3946001529693604,6.703399658203125,0.9020000100135803,0,-635,0,0,0,1,0]);
			}else if(contrast>=75){
				filter = new ColorMatrixFilter([1.2344000339508057,2.4375998973846436,0.328000009059906,0,-190.5,1.2344000339508057,2.4375998973846436,0.328000009059906,0,-190.5,1.2344000339508057,2.4375998973846436,0.328000009059906,0,-190.5,0,0,0,1,0]);
			}else if(contrast>=50){
				filter = new ColorMatrixFilter([0.6172000169754028,1.2187999486923218,0.164000004529953,0,-63.5,0.6172000169754028,1.2187999486923218,0.164000004529953,0,-63.5,0.6172000169754028,1.2187999486923218,0.164000004529953,0,-63.5,0,0,0,1,0]);
			}else if(contrast>=25){
				filter = new ColorMatrixFilter([0.41352397203445435,0.8165959119796753,0.1098799929022789,0,-21.589996337890625,0.41352397203445435,0.8165959119796753,0.1098799929022789,0,-21.589996337890625,0.41352397203445435,0.8165959119796753,0.1098799929022789,0,-21.589996337890625,0,0,0,1,0]);
			}else if(contrast>=0){
				filter = new ColorMatrixFilter([0.3086000084877014,0.6093999743461609,0.0820000022649765,0,0,0.3086000084877014,0.6093999743461609,0.0820000022649765,0,0,0.3086000084877014,0.6093999743461609,0.0820000022649765,0,0,0,0,0,1,0]);
			}
//			filter = new ColorMatrixFilter([3.3946001529693604,6.703399658203125,0.9020000100135803,0,-635,3.3946001529693604,6.703399658203125,0.9020000100135803,0,-635,3.3946001529693604,6.703399658203125,0.9020000100135803,0,-635,0,0,0,1,0]);
			
			return filter;
		}
		
		public static function getRemoveNoiseFilter(diameter:int=5):BitmapFilter{
			return new BlurFilter(diameter,diameter,3);
		}
		
		public static function getEdgeDetectionFilter():BitmapFilter{
			return new ConvolutionFilter(3,3,[0, -5, 0, -5, 20, -5, 0, -5, 0],0.2,0,true,true,0x000000,0);
//			return new ConvolutionFilter(3,3,[0, -5, 0, -5, 20, -5, 0, -5, 0],0.2,0,true,true,0xFFFFFF,0);
		}
		
		public static function getMonoFilter():BitmapFilter{
			return new ColorMatrixFilter([0.3086000084877014,0.6093999743461609,0.0820000022649765,0,99.99999237060547,0.3086000084877014,0.6093999743461609,0.0820000022649765,0,99.99999237060547,0.3086000084877014,0.6093999743461609,0.0820000022649765,0,99.99999237060547,0,0,0,1,0]);
		}

		public static function getColorBoost() : BitmapFilter{
			return new ColorMatrixFilter([33.816200256347656,-20.110198974609375,-2.7060000896453857,0,-1735,-10.18380069732666,23.889801025390625,-2.7060000896453857,0,-1735,-10.18380069732666,-20.110198974609375,41.29399871826172,0,-1735,0,0,0,1,0]);			
		}
		
		public static function getAdjustBrightness(num:int=100) : BitmapFilter {
			return new ColorMatrixFilter([1,0,0,0,num,0,1,0,0,num,0,0,1,0,num,0,0,0,1,0]);
		}
	}
}
